package router

import (
	"ci-control-backend/common/httpx"
	"ci-control-backend/controller"
	"ci-control-backend/middleware"
	"github.com/gin-gonic/gin"
)

var planController *controller.PlanController

func init() {
	planController = new(controller.PlanController)
}

func SetupPlanRoutes(r *gin.Engine) {
	// 以下API无需验证
	noAuth := r.Group("/plan")
	noAuth.Use()
	{
		noAuth.GET("/start/:key", httpx.Controller(planController.StartBuildHook))
	}

	// 以下API需要用户权限
	userAuth := r.Group("/plan")
	userAuth.Use(httpx.Middleware(middleware.UserAuth))
	{
		userAuth.POST("/new", httpx.Controller(planController.NewPlan))
		userAuth.DELETE("/:id", httpx.Controller(planController.DelPlan))
		userAuth.PUT("/:id", httpx.Controller(planController.UpdatePlan))
		userAuth.GET("/list", httpx.Controller(planController.GetPlanList))
		userAuth.GET("/hookKey", httpx.Controller(planController.GetHookKeys))
		userAuth.GET("/start", httpx.Controller(planController.StartBuild))
	}
}
